home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / winlib.lzh / WINLIB / TIMER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-30  |  1.7 KB  |  73 lines

  1. /********************************************************************
  2.  *                                                                    *
  3.  *    Timer module                                                    *
  4.  *                                                                    *
  5.  *    Copyright (c) Clever Bits and Bitgate Software 1993 - 1994        *
  6.  *    All Rights Reserved.                                            *
  7.  *                                                                    *
  8.  *    Deals with timers in a task-switching method.                    *
  9.  *                                                                    *
  10.  ********************************************************************
  11.  *                                                                    *
  12.  *    Update log:                                                        *
  13.  *                                                                    *
  14.  *    [27.03.94 - 30.03.94] Ken Hollis                                *
  15.  *        WTimerStat            - removed                                *
  16.  *        (global)            - updated all timer routines to handle    *
  17.  *                                timers in window structures            *
  18.  *                            - added WCallTMDDispatcher to timers    *
  19.  *                                                                    *
  20.  ********************************************************************/
  21.  
  22. #include <time.h>
  23.  
  24. #include "winlib.h"
  25.  
  26. #ifdef __TURBOC__
  27. #pragma warn -pia
  28. #endif
  29.  
  30. #ifndef __TIMER__
  31. #define __TIMER__
  32. #endif
  33.  
  34. /*
  35.  *    Start timer
  36.  */
  37. GLOBAL void WStartTimer(WINDOW *win)
  38. {
  39.     win->timer.clock = clock() * 1000 / CLK_TCK + win->timer.ev_mtcount;
  40.     win->timer.status = TRUE;
  41.  
  42.     WCallTMDDispatcher(win, T_RUNNING);
  43. }
  44.  
  45. /*
  46.  *    Stop timer
  47.  */
  48. GLOBAL void WStopTimer(WINDOW *win)
  49. {
  50.     win->timer.status = FALSE;
  51.  
  52.     WCallTMDDispatcher(win, T_STOPPED);
  53. }
  54.  
  55. /*
  56.  *    Register new timer
  57.  *
  58.  *    status = status of timer
  59.  *    ev_tcount = counter time in milliseconds
  60.  *    TmrDispatcher = timer dispatcher
  61.  *    user = pointer to user defined structure
  62.  */
  63. GLOBAL void WCreateTimer(WINDOW *win, int status, long ev_tcount, void *user)
  64. {
  65.     win->timer.ev_mtcount = ev_tcount;
  66.     win->timer.user = user;
  67.  
  68.     if (status)
  69.         WStartTimer(win);
  70.     else
  71.         WStopTimer(win);
  72. }
  73.